/**
 * 时间格式化工具
 * @param {Date|number} time - Date对象或时间戳
 * @param {boolean} [includeTime=false] - 是否包含时间部分
 * @returns {string} 格式化后的时间字符串
 */
export function formatTime(time, includeTime = false) {
    // 类型检查和处理
    let date;
    if (time instanceof Date) {
        date = time;
    } else if (typeof time === 'number') {
        // 检查是否是有效的时间戳
        if (time < 0 || isNaN(time)) {
            date = new Date();
        } else {
            date = new Date(time);
        }
    } else {
        // 如果传入无效值，返回当前时间
        date = new Date();
    }
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');

    if (!includeTime) {
        return `${year}-${month}-${day}`;
    }

    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    const seconds = String(date.getSeconds()).padStart(2, '0');

    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}


function isWeekend(date) {
    const utcDate = new Date(date).toISOString(); // 转换为 UTC 时间
    const dayOfWeek = new Date(utcDate).getUTCDay(); // 获取 UTC 星期几
    return dayOfWeek === 0 || dayOfWeek === 6; // 判断是否为周六或周日
}
